<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>增加业主信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../assets/js/jquery-1.8.3.min.js"></script>
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>

<body>
<div class="layui-fluid">
    <div class="layui-row" style="margin-left: 30%">
        <div class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="oname" maxlength="5" required="" autocomplete="off" class="layui-input"></div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span></div>
            </div>
<!--
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>性别</label>
                <div class="layui-input-inline">
                    <input type="text" id="osex" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
-->
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>性别
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrller" id="osex">
                        <option value="0">请选择</option>
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>年龄</label>
                <div class="layui-input-inline">
                    <input type="text" id="oage" maxlength="3" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>人口</label>
                <div class="layui-input-inline">
                    <input type="text" id="oparent" maxlength="2" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>身份证号</label>
                <div class="layui-input-inline">
                    <input type="text" id="onumber" maxlength="18" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>手机</label>
                <div class="layui-input-inline">
                    <input type="text" id="ophone" maxlength="11" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>工作单位</label>
                <div class="layui-input-inline">
                    <input type="text" id="ocompany" name="username" required="" lay-verify="nikename"
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>平方</label>
                <div class="layui-input-inline">
                    <input type="text" id="hsize" maxlength="3" name="username" required="" lay-verify="nikename" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>单元
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrller" id="uid">
                        <option value="0">请选择</option>
                        <option value="1">一单元</option>
                        <option value="2">二单元</option>
                        <option value="3">三单元</option>
                        <option value="4">四单元</option>
                        <option value="5">五单元</option>
                        <option value="6">六单元</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>楼号
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrllern" id="nid">
                        <option value="0">请选择</option>
                        <option value="1">一号楼</option>
                        <option value="2">二号楼</option>
                        <option value="3">三号楼</option>
                        <option value="4">五号楼</option>
                        <option value="5">六号楼</option>
                        <option value="6">七号楼</option>
                        <option value="7">八号楼</option>
                        <option value="8">九号楼</option>
                        <option value="9">十号楼</option>
                        <option value="10">十一号楼</option>
                        <option value="11">十二号楼</option>
                        <option value="12">十三号楼</option>
                        <option value="13">十四号楼</option>
                        <option value="14">十五号楼</option>
                        <option value="15">十六号楼</option>
                        <option value="16">十七号楼</option>
                        <option value="17">十八号楼</option>
                        <option value="18">十九号楼</option>
                        <option value="19">二十号楼</option>

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>房屋类型
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrller" id="tid">
                        <option value="0">请选择</option>
                        <option value="1">一室一厅一卫</option>
                        <option value="2">二室一厅二卫</option>
                        <option value="3">三室一厅一卫</option>
                        <option value="4">三室一厅二卫</option>
                        <option value="5">三室二厅二卫</option>
                        <option value="6">三室二厅三卫</option>
                        <option value="7">四室一厅二卫</option>
                        <option value="8">四室二厅二卫</option>
                        <option value="9">四室二厅三卫</option>
                        <option value="10">四室一厅三卫</option>

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>层数
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrller" id="hfloor">
                        <option value="0">请选择</option>
                        <option value="1">一楼</option>
                        <option value="2">二楼</option>
                        <option value="3">三楼</option>
                        <option value="4">四楼</option>
                        <option value="5">五楼</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>房间号
                </label>
                <div class="layui-input-inline layui-show-xs-block">
                    <select name="contrller" id="hno">
                        <option value="0">请选择</option>
                        <option value="1">101</option>
                        <option value="2">102</option>
                        <option value="3">201</option>
                        <option value="4">202</option>
                        <option value="5">301</option>
                        <option value="6">302</option>
                        <option value="7">401</option>
                        <option value="8">402</option>
                        <option value="9">501</option>
                        <option value="10">502</option>
                        <option value="11">601</option>
                        <option value="12">602</option>
                        <option value="13">701</option>
                        <option value="14">702</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" id="butt">增加</button>
            </div>
        </div>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
    });</script>

</body>

</html>
<script type="text/javascript" src="../assets/js/jquery-1.8.3.min.js"></script>
<script>


    $("#butt").click(function () {
        let oname = $("#oname").val();
        let osex = $("#osex option:selected").text();
        let oage = $("#oage").val();
        let oparent = $("#oparent").val();
        let onumber = $("#onumber").val();
        let ophone = $("#ophone").val();
        let ocompany = $("#ocompany").val();
        let hsize = $("#hsize").val();
        let uid = $("#uid option:selected").val();//单元
        let nid = $("#nid option:selected").val();//楼号
        let tid = $("#tid option:selected").val();//房屋类型
        let hno = $("#hno option:selected").text();//房间号
        let hfloor = $("#hfloor option:selected").text();//楼层

        let flag = true;
        if (oname == "" || osex == "" || oage == "" || oparent == "" || onumber == "" || ophone == "" || ocompany == "" || nid == "" || uid == "" || hno == "" || hsize == "" || hfloor == "" || tid == "") {
            layer.msg('注册信息填写完整!', {
                icon: 2, time: 800
            });
            flag = false;
        }
            var phone = /^1[3|4|5|8][0-9]\d{4,8}$/;
        if (flag) {
            if (!phone.test(ophone)) {
                layer.msg('请输入正确的手机号码!', {
                    icon: 2, time: 800
                });
                flag = false;
            }
        }
        if (flag) {
            if (osex != "男" & osex != "女") {
                layer.msg('性别输入有误!', {
                    icon: 2, time: 800
                });
                flag = false;
            }
        }
        var r = /^\+?[1-9][0-9]*$/;　　//判断是否为正整数
        if (flag) {
            if (!r.test(oage)) {
                layer.msg('请输入正确的年龄!', {
                    icon: 2, time: 800
                });
                flag = false;
            }
        }
        if (flag) {
            layui.use(['table', 'jquery'], function () {
                var table = layui.table;
                var $ = layui.jquery;
                $.ajax({
                    type: "POST",
                    url: "http://localhost:8080/api/insertuser",
                    data: {
                        "oname": oname,
                        "osex": osex,
                        "oage": oage,
                        "oparent": oparent,
                        "onumber": onumber,
                        "ophone": ophone,
                        "ocompany": ocompany,
                        "nid": nid,
                        "uid": uid,
                        "hno": hno,
                        "hsize": hsize,
                        "hfloor": hfloor,
                        "tid": tid
                    },
                    headers: {
                        token: localStorage.getItem("token")
                    },
                    datatype: "json",
                    success: function (data) {
                        if (data!="") {
                            var index = parent.layer.getFrameIndex(window.name);
                            layer.msg('业主信息增加成功!',{
                                icon:1
                                ,time:1000
                            },function (){
                                parent.layer.close(index);//关闭当前页
                            });
                        }
                    }
                })
            })
        }
    })


</script>